<template>
  <section v-if="isShow && url" class="inner-dialog-wrap" @click="back">
    <div class="dialog">
      <!--<iframe :src="url" frameborder="0"></iframe>-->
    </div>
  </section>
</template>

<script>
  import _ from 'lodash'
  import moment from 'moment'
  export default {
    name: 'redBirthday',
    data () {
      return {
        url: '',
        isShow: !true
      }
    },
    created () {
      // this.birthday()
    },
    methods: {
      birthday () {
        let uid = this.$store.state.userInfo.id
        let openedKey = 'hasShowBirthDay' + uid + moment().format('YYYY-M-D')
        if (this.$localStorage.get(openedKey)) return false
        this.fetchService.birthday(uid).then(res => {
          if (res.data.todayIsBirthDay === '1') {
            this.$store.state.birthdayIsOpened = true
            this.url = res.data.url || 'http://222.85.156.70:8888/zzhk.html?token=' + this.tools.getToken()
            let query = this.tools.getQuery(this.url)
            this.url = this.tools.setQuery(this.url, _.extend(query, {token: this.tools.getToken()}))
            console.log('打开政治贺卡', this.url)
            this.$store.state.birthdayUrl = this.url
            // 记录当前用户是否打开过政治贺卡
            try {
              this.openUrl(this.url)
              this.$localStorage.set(openedKey, true)
              this.logEvent(0, {content_type: 0, content_title: '弹出政治贺卡'})
            } catch (e) {
              this.$localStorage.set(openedKey, false)
            }
          }
        })
      },
      openUrl (url) {
        if (window.android && window.android.openUrlAdapt) {
          window.android.openUrlAdapt(url)
        }
      },
      show () {
        this.birthday()
        return this
        // this.isShow = true
      },
      back () {
        this.isShow = false
      }
    }
  }
</script>

<style scoped lang="scss">
  .dialog {
    width:80%;
  }
  iframe {
    border:none;
    width:100%;
    height:65vh;
    border-radius:10px;
    overflow:hidden;
    overflow-y:auto;
    background:rgba(#fff, .7);
  }
</style>
